package com.gqr.syc;

/*
 * 演示线程不安全
 *
 * */
public class ShowUnsafe2 implements Runnable {
    static ShowUnsafe2 r = new ShowUnsafe2();
    static int i = 0;

    @Override
    public void run() {
        synchronized (ShowUnsafe2.class) {
            for (int j = 0; j < 100000; j++) {
                i++;
            }
        }

    }


    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(r);
        Thread t2 = new Thread(r);
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(i);
    }
}
